package com.hx.delegate.mvc;

import com.hx.delegate.mvc.controllers.OrderController;
import com.hx.delegate.mvc.controllers.SystemController;
import com.hx.delegate.mvc.controllers.UserController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author： Huathy
 * @ClassPath： com.hx.delegate.mvc.DispatcherServlet
 * @Date： 2021-08-30 21:24
 * @Description：
 */
public class DispatcherServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //完成调度
        doDispatch(req,resp);
    }

    private void doDispatch(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String uri = req.getRequestURI();
        String id = req.getParameter("id");
        if("getUserById".equals(uri)){
            new UserController().getUserById(id);
        }else if("getOrderById".equals(uri)){
            new OrderController().getOrderById(id);
        }else if("logout".equals(uri)){
            new SystemController().logout(id);
        }else{
            resp.getWriter().println("<h1>404 Not Found！404错误！请求资源没有找到！</h1>");
        }
    }
}
